package com.cxyjy.cfyuiapi.controller;

import com.cxyjy.cfyuiapi.service.ComfyUIDownloadService;
import com.cxyjy.common.util.JResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: jony
 * @Date : 2024/11/20 14:06
 * @VERSION v1.0
 */
@RestController
public class ComfyUIDownloadController {
    @Autowired
    ComfyUIDownloadService comfyUIDownloadService;

    /**
     * 下载视频接口
     * <p>
     * 将view接口返回的视频流转换成字节流写入outputStream中供下载
     *
     * @param promptId
     * @param httpServletResponse
     * @throws IOException
     */
    @GetMapping("/downloadVideo")
    public void downloadVideo(@RequestParam String promptId, HttpServletResponse httpServletResponse) throws IOException {
        comfyUIDownloadService.downloadVideo(promptId, httpServletResponse);
    }

    @GetMapping("/downloadImage")
    public void downloadImage(@RequestParam String promptId, HttpServletResponse httpServletResponse) throws IOException {
        comfyUIDownloadService.downloadImage(promptId, httpServletResponse);
    }

    @GetMapping("/checkPromptId")
    public JResponse checkPromptId(@RequestParam String promptId) throws IOException {
        return comfyUIDownloadService.checkPromptId(promptId);
    }

    @GetMapping("/downloadVideoTest")
    public void downloadVideoTest(@RequestParam String promptId, HttpServletResponse httpServletResponse) throws IOException {
        comfyUIDownloadService.downloadVideoTest(promptId, httpServletResponse);
    }


}
